<?php

defined('SYSPATH') OR die('No direct access allowed.');

class Controller_Gallery extends Controller_Initialize {

  public $secure_actions = array(
      // user actions
  );

  /*
   * 
  public $auth;
  public $session;
  public $session_id;

  public function before() {
    parent::before();

    ($_SERVER['HTTP_USER_AGENT'] === 'Shockwave Flash' AND ($this->session_id = Security::xss_clean(arr::get($_POST, 'session', null))));
    $this->session = Session::instance(NULL, $this->session_id);
    $this->auth = Auth::instance();
  }
   *
   */

  public function action_index() {

    $this->template->title = '&ndash; Galerie';
    $this->template->navigation->active = 'gallery';

    $view = View::factory('templates/gallery/index')
      ->bind('photo_user', $result)
      ->bind('pagination', $pagination)
      ->bind('sort', $sort);

    $photo_user = ORM::factory('photo_user')->where('user_profile_only', '=', null);

    $total_items = $photo_user->count_all();

    $pagination = new Pagination(array(
      'current_page' => array('source' => 'route', 'key' => 'page'),
      'total_items' => $total_items,
      'items_per_page'=> 6,
      'auto_hide' => true,
    ));


    $result = $photo_user->limit($pagination->items_per_page)->offset($pagination->offset)->where('user_profile_only', '=', null)->or_where('user_hidden', '=', null)->find_all();

    $this->template->content = $view;

  }

  public function action_random() {

    $this->template->title = '&ndash; Galerie';
    $this->template->navigation->active = 'gallery';

    $view = View::factory('templates/gallery/index')
      ->bind('photo_user', $result)
      ->bind('pagination', $pagination)
      ->bind('sort', $sort);

    $photo_user = ORM::factory('photo_user')->where('user_profile_only', '=', null);

    $pagination = new Pagination(array(
      'current_page' => array('source' => 'route', 'key' => 'page'),
      'total_items' => 6,
      'items_per_page'=> 6,
      'auto_hide' => true,
    ));


    $result = $photo_user->limit($pagination->items_per_page)->offset($pagination->offset)->where('user_profile_only', '=', null)->or_where('user_hidden', '=', null)->order_by(DB::expr('RAND()'))->find_all();

    $this->template->content = $view;

  }

}